var MixlyTitle = {};

if (MixlyUrl.BOARD_CONFIG?.software?.version && MixlyUrl.BOARD_CONFIG?.boardName) {
    MixlyTitle.title = MixlyUrl.BOARD_CONFIG.software.version + " For " + MixlyUrl.BOARD_CONFIG.boardName;
    document.title = MixlyTitle.title;
} else {
    MixlyTitle.title = document.title;
}
MixlyTitle.NOWTITLE = MixlyTitle.title;

MixlyTitle.updeteVersionNumber = function (newVersionNumber) {
    try {
        MixlyTitle.NOWTITLE = document.title.replace(/Mixly[\s]?[\d.]+/g, "Mixly " + newVersionNumber);
        document.title = MixlyTitle.NOWTITLE;
    } catch (e) {
        console.log(e);
    }
}

MixlyTitle.getVersionNumber = function () {
    try {
        MixlyTitle.NOWTITLE = document.title.match(/Mixly[\s]?[\d.]+/g);
        return MixlyTitle.NOWTITLE;
    } catch (e) {
        console.log(e);
        return "";
    }
}

MixlyTitle.updeteFilePath = function (newPath) {
    try {
        var pathArr = MixlyTitle.NOWTITLE.match(/\([^\n\r]+\)/g);
        if (pathArr) {
            MixlyTitle.NOWTITLE = document.title.replace(/\([^\n\r]+\)/g, "(" + newPath + ")");
            document.title = MixlyTitle.NOWTITLE;
        } else {
            MixlyTitle.NOWTITLE = document.title + " (" + newPath + ")";
            document.title = MixlyTitle.NOWTITLE;
        }
    } catch (e) {
        console.log(e);
    }
}

MixlyTitle.getFilePath = function () {
    try {
        let filePathArr = document.title.match(/(?<=\()[^\n\r]+(?=\))/g);
        if (filePathArr && filePathArr.length > 0) {
            return filePathArr[0];
        }
    } catch (e) {
        console.log(e);
    }
    return null;
}

MixlyTitle.updateTitle = function (newTitle) {
    MixlyTitle.NOWTITLE = newTitle;
    document.title = newTitle;
}